﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_AdminInformationEdit : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            int ID = -1;
            ID = Shove._Convert.StrToInt(Shove._Web.Utility.GetRequest("ID"), -1);

            if (ID < 0)
            {
                PublicFunction.GoError(ErrorNumber.Unknow, "参数错误", this.GetType().BaseType.FullName);

                return;
            }

            tbID.Text = ID.ToString();

            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页

 //       RequestCompetences = Competences.BuildCompetencesList(Competences.EditNews);//页面权限

        base.OnLoad(e);
    }

    #endregion

    private void BindData()
    {
        DataTable dt = new DAL.Tables.tbl_Information().Open("", "ID = " + Shove._Convert.StrToLong(tbID.Text,-1).ToString(), "");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        Shove.ControlExt.SetDownListBoxTextFromValue(ddlType, dt.Rows[0]["Type"].ToString());

        tbDateTime.Text = dt.Rows[0]["DateTime"].ToString();
        cbisShow.Checked = Shove._Convert.StrToBool(dt.Rows[0]["isShow"].ToString(), true);
        tbTitle.Text = dt.Rows[0]["Title"].ToString();
        try
        {
            tbContent.Value = Shove._String.Decompress((byte[])dt.Rows[0]["Content"]);
        }
        catch { }
    }

    protected void btnSave_Click(object sender, System.EventArgs e)
    {
        DateTime dt = System.DateTime.Now;
        try
        {
            dt = System.DateTime.Parse(tbDateTime.Text);
        }
        catch
        {
            Shove._Web.JavaScript.Alert(this.Page, "时间格式错误，请输入如“" + dt.ToString() + "”的时间格式。");

            return;
        }

        string Title = tbTitle.Text.Trim();
        if (Title == "")
        {
            Shove._Web.JavaScript.Alert(this.Page, "请输入标题。");

            return;
        }

        DAL.Tables.tbl_Information Information = new DAL.Tables.tbl_Information();

        Information.DateTime.Value = dt;
        Information.Title.Value = Title;
        Information.Content.Value = Shove._String.Compress(tbContent.Value);
        Information.isShow.Value = cbisShow.Checked;
        Information.Type.Value = Shove._Convert.StrToInt(ddlType.SelectedValue, 1);

        if (Information.Update("[ID] = " + tbID.Text) < 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "信息修改失败。");

            return;
        }

        this.Response.Redirect("AdminInformation.aspx", true);
    }
}